<?php

namespace App\Http\Controllers\Auth;

use App\Repositories\IndexRepository;
use App\Http\Controllers\Controller;

class WxAuthController extends Controller
{
    /*
     * 获取用户信息
     */
    public function getWxUserInfo()
    {
        //$response = app('EasyWechatOfficial')->oauth->scopes(['snsapi_userinfo'])->redirect();
        $response = app('EasyWechatOfficial')->oauth->redirect();
        return $response;
    }

    /*
     * wxauth_callback
     */
    public function WxauthCallback(IndexRepository $indexRepository)
    {
        $user_info = app('EasyWechatOfficial')->oauth->user()->getOriginal();

        $wx_user = $indexRepository->CreateOrUpdateWxuser($user_info);

        session([config('services.wechat.wauth_session_name')=>$wx_user]);

        return redirect('/');
    }
}
